package cn.stylefeng.guns.modular.tool.service.impl;

import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.multipart.MultipartFile;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.basic.entity.BasicCustomer;
import cn.stylefeng.guns.modular.basic.service.BasicCustomerService;
import cn.stylefeng.guns.modular.tool.entity.ToolExpress;
import cn.stylefeng.guns.modular.tool.mapper.ToolExpressMapper;
import cn.stylefeng.guns.modular.tool.model.params.ToolExpressExcelParam;
import cn.stylefeng.guns.modular.tool.model.params.ToolExpressParam;
import cn.stylefeng.guns.modular.tool.model.params.ToolExpressScanParam;
import cn.stylefeng.guns.modular.tool.model.params.ToolExpressSumParam;
import cn.stylefeng.guns.modular.tool.model.params.ToolExpressSumTaskParam;
import cn.stylefeng.guns.modular.tool.model.params.ToolGoodsInstallParam;
import cn.stylefeng.guns.modular.tool.model.params.ToolTaskArrangeParam;
import cn.stylefeng.guns.modular.tool.model.result.ToolExpressExcelResult;
import cn.stylefeng.guns.modular.tool.model.result.ToolExpressResult;
import cn.stylefeng.guns.modular.tool.model.result.ToolGoodsInstallResult;
import cn.stylefeng.guns.modular.tool.model.result.ToolTaskArrangeResult;
import cn.stylefeng.guns.modular.tool.service.ToolExpressExcelService;
import cn.stylefeng.guns.modular.tool.service.ToolExpressScanService;
import  cn.stylefeng.guns.modular.tool.service.ToolExpressService;
import cn.stylefeng.guns.modular.tool.service.ToolExpressSumService;
import cn.stylefeng.guns.modular.tool.service.ToolExpressSumTaskService;
import cn.stylefeng.guns.modular.tool.service.ToolGoodsInstallService;
import cn.stylefeng.guns.modular.tool.service.ToolTaskArrangeService;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;

/**
 * 快递统计管理 服务实现类
 */
@Service
public class ToolExpressServiceImpl extends ServiceImpl<ToolExpressMapper, ToolExpress> implements ToolExpressService {

    @Override
    public void add(ToolExpressParam param){
        ToolExpress entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(ToolExpressParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(ToolExpressParam param){
        ToolExpress oldEntity = getOldEntity(param);
        ToolExpress newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public ToolExpressResult findBySpec(ToolExpressParam param){
        return this.baseMapper.findBySpec(param);
    }

    @Override
    public List<ToolExpressResult> findListBySpec(ToolExpressParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(ToolExpressParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findPageBySpecFind(ToolExpressParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findPageBySpecFind(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findPageBySpec2(ToolExpressParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList2(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findwellenPageBySpec(ToolExpressParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findwellenPageBySpec(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(ToolExpressParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private ToolExpress getOldEntity(ToolExpressParam param) {
        return this.getById(getKey(param));
    }

    private ToolExpress getEntity(ToolExpressParam param) {
        ToolExpress entity = new ToolExpress();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

    @Resource
    private ToolExpressExcelService toolExpressExcelService;
    @Resource
    private BasicCustomerService basicCustomerService;

	@Override
	@Transactional(rollbackFor = Exception.class,timeout = 600)
	public ResponseData getExceldata(MultipartFile file,Long waveId,Long customerId, ResponseData data) throws IOException{
        User user = userService.getcurrentUser();
        BasicCustomer basicCustomer = basicCustomerService.getById(customerId);
		String fileName = file.getOriginalFilename();
		List<ToolExpressExcelParam> list = new ArrayList<ToolExpressExcelParam>();
		
		if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
			data.setMessage("上传文件格式不正确");
			data.setSuccess(false);
        }

		boolean isExcel2003 = true;
        if (fileName.matches("^.+\\.(?i)(xlsx)$")) {
            isExcel2003 = false;
        }
        InputStream is = file.getInputStream();
        Workbook wb = null;
        if (isExcel2003) {
            wb = new HSSFWorkbook(is);
        } else {
            wb = new XSSFWorkbook(is);
        }
        Sheet sheet = wb.getSheetAt(0);
        
        for (int r = 1; r <= sheet.getLastRowNum()+1; r++) {
        	Row row = sheet.getRow(r);
            if (row == null){
                continue;
            }
            ToolExpressExcelParam toolExpressExcelParam = new ToolExpressExcelParam();

            String  v1 = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(0));
            if (ToolUtil.isNotEmpty(v1)) {
            	toolExpressExcelParam.setOutNumber(v1);//出库单号
			} else {
				break;
			}

            String v2 = getCellValue(row.getCell(1));
            if (ToolUtil.isNotEmpty(v2)) {
            	toolExpressExcelParam.setV2(v2);//快递公司
			}
            
            String  orderNumber = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(2));
            if (ToolUtil.isNotEmpty(orderNumber)) {
            	toolExpressExcelParam.setOrderNumber(orderNumber);//快递单号
			}

            String v3 = getCellValue(row.getCell(3));
            if (ToolUtil.isNotEmpty(v3)) {
            	toolExpressExcelParam.setV3(v3);//省份
			}

            String v4 = getCellValue(row.getCell(4));
            if (ToolUtil.isNotEmpty(v4)) {
            	toolExpressExcelParam.setV4(v4);//城市
			}

            String v5 = getCellValue(row.getCell(5));
            if (ToolUtil.isNotEmpty(v5)) {
            	toolExpressExcelParam.setV5(v5);//区县
			}

            String v6 = getCellValue(row.getCell(6));
            if (ToolUtil.isNotEmpty(v6)) {
            	toolExpressExcelParam.setV6(v6);//街道
			}
            
            String v7 = "";
            if(ToolUtil.isNotEmpty(toolExpressExcelParam.getV3())) {
            	v7 += toolExpressExcelParam.getV3();
            	if(ToolUtil.isNotEmpty(toolExpressExcelParam.getV4())) {
                	v7 += toolExpressExcelParam.getV4();
                	if(ToolUtil.isNotEmpty(toolExpressExcelParam.getV5())) {
                    	v7 += toolExpressExcelParam.getV5();
                    	if(ToolUtil.isNotEmpty(toolExpressExcelParam.getV6())) {
                        	v7 += toolExpressExcelParam.getV6();
                    	}
                	}
            	}
            }
            toolExpressExcelParam.setV7(v7);

            String sku_id = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(7));
            if (ToolUtil.isNotEmpty(sku_id)) {
	        	if(sku_id.equals("1759947952444423")||sku_id.equals("1759325202211891")||sku_id.equals("4967199140507")||sku_id.equals("1759325202211890")
	        			||sku_id.equals("1759947952444420")||sku_id.equals("687374017518")||sku_id.equals("693717971892")
	        			||sku_id.equals("caixiang")
	        			||sku_id.equals("qipaodai-05")
	        			||sku_id.equals("goodcard5")
	        			||sku_id.equals("goodcard2")
	        			||sku_id.equals("TM-R0")||sku_id.equals("TM-NK")
	        			||sku_id.equals("TM-RO")
	        			||sku_id.equals("zhixiang")||sku_id.equals("zhixiang-A1")||sku_id.equals("zhixiang-A3")
	        			||sku_id.equals("会员福利卡")||sku_id.equals("瑜大公子卡片")||sku_id.equals("纸箱包装")) {
	        		continue;
	        	}
            	toolExpressExcelParam.setGoodsNumber(sku_id);//商品编号
			} else {
				return ResponseData.error("导入数据中商品编号不得为空!");
			}

            String num = getCellValue(row.getCell(8));
            if (ToolUtil.isNotEmpty(num)) {
            	toolExpressExcelParam.setNum(num);//数量
			} else {
				return ResponseData.error("导入数据中数量不得为空!");
			}
            
            toolExpressExcelParam.setWaveId(waveId);
            toolExpressExcelParam.setCustomerId(customerId);
            toolExpressExcelParam.setCustomerName(basicCustomer.getCustomerName());
            toolExpressExcelParam.setDeptId(user.getDeptId());
            list.add(toolExpressExcelParam);
        }
        
        ToolExpressExcelParam ToolExpressExceldelete = new ToolExpressExcelParam();
        ToolExpressExceldelete.setWaveId(waveId);
        ToolExpressExceldelete.setCustomerId(customerId);
        ToolExpressExceldelete.setLastDay("1");
        toolExpressExcelService.deleteBySpec(ToolExpressExceldelete);
        toolExpressExcelService.saveBatchList(list);
        ToolExpressExcelParam excelParam = new ToolExpressExcelParam();
        excelParam.setWaveId(waveId);
        excelParam.setCustomerId(customerId);
		List<ToolExpressExcelResult> listr = toolExpressExcelService.findListBySpec(excelParam);

		List<ToolExpressParam> listadd = new ArrayList<ToolExpressParam>();
        for (ToolExpressExcelResult p : listr) {
			boolean order = false;
			for (int i = 0; i < listadd.size(); i++) {
				if(listadd.get(i).getV1().equals(p.getOutNumber())) {
					order = true;
					boolean goods = false;
					for (ToolExpressParam tp2 : listadd.get(i).getList()) {
						if(tp2.getGoodsNumber().equals(p.getGoodsNumber())){
							goods = true;
							BigDecimal num = new BigDecimal(tp2.getNum());
							BigDecimal nump = new BigDecimal(p.getNum());
							tp2.setNum(num.add(nump)+"");
							break;
						}
					}
					if(!goods) {
						ToolExpressParam pnew = new ToolExpressParam();
						pnew.setGoodsNumber(p.getGoodsNumber());
						pnew.setNum(p.getNum());
						listadd.get(i).getList().add(pnew);
						break;
					} else {
						break;
					}
				}
			}
			if(!order) {
				ToolExpressParam pnew = new ToolExpressParam();
				pnew.setOrderNumber(p.getOrderNumber());
				pnew.setV1(p.getOutNumber());
				pnew.setV3(p.getV2());
				pnew.setV4(p.getV3());
				pnew.setV5(p.getV4());
				pnew.setV6(p.getV5());
				pnew.setV7(p.getV6());
				pnew.setV8(p.getV7());
				
				List<ToolExpressParam> newlist = new ArrayList<ToolExpressParam>();
				
				ToolExpressParam plistnew = new ToolExpressParam();
				plistnew.setGoodsNumber(p.getGoodsNumber());
				plistnew.setNum(p.getNum());
				
				newlist.add(plistnew);
				pnew.setList(newlist);
				
				listadd.add(pnew);
			}
		}

        ToolGoodsInstallParam installParam = new ToolGoodsInstallParam();
        installParam.setCustomerId(customerId);
        installParam.setDeptId(user.getDeptId());
        List<ToolGoodsInstallResult> listin = toolGoodsInstallService.findListBySpec(installParam,user.getOperateId());//查询品类的重量
		List<ToolExpressParam> add = new ArrayList<ToolExpressParam>();
        for (ToolExpressParam p : listadd) {
        	ToolExpressParam addp = new ToolExpressParam();
        	addp.setOrderNumber(p.getOrderNumber());
        	addp.setV1(p.getV1());
        	addp.setV3(p.getV3());
        	addp.setV4(p.getV4());
        	addp.setV5(p.getV5());
        	addp.setV6(p.getV6());
        	addp.setV7(p.getV7());
        	addp.setV8(p.getV8());
        	BigDecimal snum = new BigDecimal(0);
        	BigDecimal weightsum = new BigDecimal(0);
        	String goodsnumber = "";
        	for (ToolExpressParam p2 : p.getList()) {
            	BigDecimal snum2 = new BigDecimal(p2.getNum());
        		snum = snum.add(snum2);
        		goodsnumber += p2.getGoodsNumber()+"*"+p2.getNum().replace(".0", "")+"，";
        		for (ToolGoodsInstallResult in : listin) {
					if(p2.getGoodsNumber().equals(in.getGoodsNumber())) {
		            	BigDecimal weight = new BigDecimal(in.getWeight());
		            	BigDecimal weights = weight.multiply(snum2).setScale(3, BigDecimal.ROUND_HALF_DOWN);//计算重量
		            	weightsum = weightsum.add(weights);
		            	break;
					}
				}
			}
        	addp.setNum(snum.setScale( 0, BigDecimal.ROUND_HALF_DOWN )+"");
        	addp.setGoodsNumber(goodsnumber);
        	addp.setWaveId(waveId);
        	addp.setCustomerId(customerId);
        	addp.setCustomerName(basicCustomer.getCustomerName());
        	addp.setDeptId(user.getDeptId());
        	addp.setV2(weightsum+"");
        	add.add(addp);
		}
        if(add.size()>0) {
        	ToolExpressParam ToolExpressParamDelete = new ToolExpressParam();
        	ToolExpressParamDelete.setCustomerId(customerId);
        	ToolExpressParamDelete.setWaveId(waveId);
        	ToolExpressParamDelete.setLastDay("1");
        	this.deleteBySpec(ToolExpressParamDelete);
        	this.saveBatchList(add);

			ToolExpressParam expressParam = new ToolExpressParam();
			expressParam.setWaveId(waveId);
			expressParam.setCustomerId(customerId);
			List<ToolExpressResult> exlist = this.findListBySpecSum(expressParam);
			int z = 1;
			List<ToolExpressSumParam> listaddsum = new ArrayList<ToolExpressSumParam>();
			for (ToolExpressResult r : exlist) {
				ToolExpressSumParam sumParam = new ToolExpressSumParam();
				sumParam.setWaveId(waveId);
				sumParam.setCustomerId(r.getCustomerId());
				sumParam.setCustomerName(r.getCustomerName());
				sumParam.setGoodsNumber(r.getGoodsNumber());
				sumParam.setNum(r.getNum()+"");
				sumParam.setOrderNum(r.getV1());
				sumParam.setSumNum(r.getV2());
				sumParam.setV1(z+"");
				sumParam.setDeptId(r.getDeptId());
				listaddsum.add(sumParam);
				z++;
			}
			if(listadd.size()>0) {
				ToolExpressSumParam ToolExpressSumParamdelete = new ToolExpressSumParam();
				ToolExpressSumParamdelete.setCustomerId(customerId);
				ToolExpressSumParamdelete.setWaveId(waveId);
				toolExpressSumService.deleteBySpec(ToolExpressSumParamdelete);
				toolExpressSumService.saveBatchList(listaddsum);
			}
        }
		return ResponseData.success();
	}

	@Resource
    private ToolExpressSumService toolExpressSumService;

    @Resource
    private ToolGoodsInstallService toolGoodsInstallService;

    @Resource
    private ToolExpressScanService toolExpressScanService;

    @Resource
    private ToolTaskArrangeService toolTaskArrangeService;

	@Override
	@Transactional(rollbackFor = Exception.class,timeout = 600)
	public ResponseData getExceldata3(MultipartFile file,Long waveId, ResponseData data) throws IOException{
		String fileName = file.getOriginalFilename();
		List<ToolExpressScanParam> list = new ArrayList<ToolExpressScanParam>();
		ToolTaskArrangeParam toolTaskArrangeParam = new ToolTaskArrangeParam();
		toolTaskArrangeParam.setWaveId(waveId);
		List<ToolTaskArrangeResult> arrlist = toolTaskArrangeService.findListBySpec(toolTaskArrangeParam);
		
		if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
			data.setMessage("上传文件格式不正确");
			data.setSuccess(false);
        }

		boolean isExcel2003 = true;
        if (fileName.matches("^.+\\.(?i)(xlsx)$")) {
            isExcel2003 = false;
        }
        InputStream is = file.getInputStream();
        Workbook wb = null;
        if (isExcel2003) {
            wb = new HSSFWorkbook(is);
        } else {
            wb = new XSSFWorkbook(is);
        }
        Sheet sheet = wb.getSheetAt(0);
        
        for (int r = 1; r <= sheet.getLastRowNum()+1; r++) {
        	Row row = sheet.getRow(r);
            if (row == null){
                continue;
            }
			ToolExpressScanParam param = new ToolExpressScanParam();
            
            String  v1 = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(0));//波次
            if (ToolUtil.isNotEmpty(v1)) {
    			param.setV1(v1);
			} 
            
            String  orderNumber = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(1));//快递单号
            if (ToolUtil.isNotEmpty(orderNumber)) {
            	param.setOrderNumber(orderNumber);
			} else {
				continue;
			}
            
            String  arrangeNumber = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(2));//小组编号
            if (ToolUtil.isNotEmpty(arrangeNumber)) {
            	for (ToolTaskArrangeResult arr : arrlist) {
            		if(arr.getGroupNumber().equals(arrangeNumber)) {
            			param.setArrangeId(Long.parseLong(arr.getId().toString()));
            			param.setArrangeNumber(arrangeNumber);
            			param.setUserName(arr.getGroupUsers());
            		}
            	}
			} 
            
//            String  arrangeNumber = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(2));//小组编号
//            if (ToolUtil.isNotEmpty(arrangeNumber)) {
//                String  userName = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(3));//小组人员
//                if(ToolUtil.isNotEmpty(userName)) {
//                	for (ToolTaskArrangeResult arr : arrlist) {
//                		if(arr.getGroupNumber().equals(arrangeNumber)&&arr.getGroupUsers().equals(userName)) {
//                			param.setArrangeId(Long.parseLong(arr.getId().toString()));
//                			param.setArrangeNumber(arrangeNumber);
//                			param.setUserName(arr.getGroupUsers());
//                		}
//                	}
//                }
//			} 

            String  handover = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(3));//交接次数
            if (ToolUtil.isNotEmpty(handover)) {
    			param.setHandover(handover);
			} 

            String  v2 = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(4));//类型
            if (ToolUtil.isNotEmpty(v2)) {
    			param.setV2(v2);
			} 

            String  v3 = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(5));//包材编号
            if (ToolUtil.isNotEmpty(v3)) {
    			param.setV3(v3);
			} 
            param.setWaveId(waveId);
            param.setState("待更新");
            list.add(param);
        }
        if(list.size()>0) {
        	toolExpressScanService.saveBatchList(list);
        }
		return ResponseData.success();
	}

	@Override
	@Transactional(rollbackFor = Exception.class,timeout = 600)
	public ResponseData getExceldata4(MultipartFile file,Long waveId,Long customerId, ResponseData data) throws IOException{
		User user = userService.getcurrentUser();
        BasicCustomer basicCustomer = basicCustomerService.getById(customerId);
        
		ToolTaskArrangeParam toolTaskArrangeParam = new ToolTaskArrangeParam();
		toolTaskArrangeParam.setWaveId(waveId);
		List<ToolTaskArrangeResult> arrlist = toolTaskArrangeService.findListBySpec(toolTaskArrangeParam);
		
		String fileName = file.getOriginalFilename();
    	List<ToolExpressSumTaskParam> savelist = new ArrayList<ToolExpressSumTaskParam>();
		
		if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
			data.setMessage("上传文件格式不正确");
			data.setSuccess(false);
			return data;
        }

		boolean isExcel2003 = true;
        if (fileName.matches("^.+\\.(?i)(xlsx)$")) {
            isExcel2003 = false;
        }
        InputStream is = file.getInputStream();
        Workbook wb = null;
        if (isExcel2003) {
            wb = new HSSFWorkbook(is);
        } else {
            wb = new XSSFWorkbook(is);
        }
        Sheet sheet = wb.getSheetAt(0);
        
        for (int r = 1; r <= sheet.getLastRowNum()+1; r++) {
        	Row row = sheet.getRow(r);
            if (row == null){
                continue;
            }
            ToolExpressSumTaskParam param = new ToolExpressSumTaskParam();
            
            String  arrangeNumber = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(0));//小组编号
            if (ToolUtil.isNotEmpty(arrangeNumber)) {
            	Boolean falg = false;
    			for (ToolTaskArrangeResult arr : arrlist) {
					if(arr.getGroupNumber().equals(arrangeNumber)) {
		    			param.setArrangeNumber(arrangeNumber);
						param.setArrangeId(Long.parseLong(arr.getId().toString()));
						param.setUserName(arr.getGroupUsers());
						falg = true;
						break;
					}
				}
    			if (!falg) {
    				data.setMessage("小组编号："+arrangeNumber+"未匹配到工作安排！");
    				data.setSuccess(false);
    				return data;
				}
			} else {
				continue;
			}
            
//            String  arrangeNumber = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(0));//小组编号
//            if (ToolUtil.isNotEmpty(arrangeNumber)) {
//                String  userName = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(1));//小组人员
//                if(ToolUtil.isNotEmpty(userName)){
//                	Boolean falg = false;
//        			for (ToolTaskArrangeResult arr : arrlist) {
//    					if(arr.getGroupNumber().equals(arrangeNumber)&&arr.getGroupUsers().equals(userName)) {
//    		    			param.setArrangeNumber(arrangeNumber);
//    						param.setArrangeId(Long.parseLong(arr.getId().toString()));
//    						param.setUserName(arr.getGroupUsers());
//    						falg = true;
//    						break;
//    					}
//    				}
//        			if (!falg) {
//        				data.setMessage("小组编号："+arrangeNumber+"未匹配到工作安排！");
//        				data.setSuccess(false);
//        				return data;
//    				}
//                } else {
//    				data.setMessage("小组人员不得为空！");
//    				data.setSuccess(false);
//    				return data;
//                }
//			} else {
//				continue;
//			}
            
            String  v3 = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(1));//类型
            if (ToolUtil.isNotEmpty(v3)) {
            	if(v3.equals("退货整理")||v3.equals("预包")) {
                	param.setV3(v3);
            	} else {
    				data.setMessage("类型请输入预包或退货整理，请检查数据");
    				data.setSuccess(false);
    				return data;
            	}
			} else {
				continue;
			}
            
            String  goodsNumber = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(2));//商品组合
            if (ToolUtil.isNotEmpty(goodsNumber)) {
    			param.setGoodsNumber(goodsNumber);
			} 

            String  num = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(3));//组合数量
            if (ToolUtil.isNotEmpty(num)) {
    			param.setNum(num);
			} else {
				continue;
			}

            String  sumNum = cn.stylefeng.guns.core.util.DateUtil.getCellValueByCell(row.getCell(4));//单量
            if (ToolUtil.isNotEmpty(sumNum)) {
    			param.setSumNum(sumNum);
			} else {
				continue;
			}

        	BigDecimal numb = new BigDecimal(param.getNum());//组合数
        	BigDecimal sumNumb = new BigDecimal(param.getSumNum());//单量
        	BigDecimal v1 = numb.multiply(sumNumb).setScale(2, BigDecimal.ROUND_HALF_DOWN);
        	param.setV1(v1.toString());//作业量
            param.setWaveId(waveId);
            param.setCustomerId(customerId);
            param.setCustomerName(basicCustomer.getCustomerName());
            param.setDeptId(user.getDeptId());
            savelist.add(param);
        }
    	if(savelist.size()>0) {
    		toolExpressSumTaskService.saveBatchList(savelist);
    	}
		return ResponseData.success();
	}

	@Resource
    private ToolExpressSumTaskService toolExpressSumTaskService;
	
	@Resource
    private UserService userService;

	private static String getCellValue(Cell cell) {
        if (cell == null) {
            return "";
        }
        if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
            if (DateUtil.isCellDateFormatted(cell)) {
                return HSSFDateUtil.getJavaDate(cell.getNumericCellValue()).toString();
            } else {
                return new BigDecimal(Double.toString(cell.getNumericCellValue())).toString();
            }
        } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
            return StringUtils.trimToEmpty(cell.getStringCellValue());
        } else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
            return StringUtils.trimToEmpty(cell.getCellFormula());
        } else if (cell.getCellType() == Cell.CELL_TYPE_BLANK) {
            return "";
        } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
            return String.valueOf(cell.getBooleanCellValue());
        } else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) {
            return "ERROR";
        } else {
            return cell.toString().trim();
        }
    }

	@Override
	public List<ToolExpressResult> findListBySpecSum(ToolExpressParam expressParam) {
		return this.baseMapper.findListBySpecSum(expressParam);
	}

	@Override
	public void deleteBySpec(ToolExpressParam expressParam) {
		this.baseMapper.deleteBySpec(expressParam);
	}

	@Override
	public boolean saveBatchList(List<ToolExpressParam> list) {
		return this.baseMapper.saveBatchList(list);
	}

	@Override
	public void updateBySpec(ToolExpressParam expressParam) {
		this.baseMapper.updateBySpec(expressParam);
	}

	@Override
	public List<ToolExpressResult> findStopOrderListBySpec(ToolExpressParam param) {
		return this.baseMapper.findStopOrderListBySpec(param);
	}
}
